package avicit.bdp.dds.api.controller;

import avicit.bdp.common.dto.query.dds.ProcessDefinitionQuery;
import avicit.bdp.dds.dao.entity.ProcessDefinition;
import avicit.bdp.dds.dao.mapper.ProcessDefinitionMapper;
import avicit.platform6.core.exception.BusinessException;
import avicit.platform6.core.exception.BusinessException;
import avicit.platform6.core.rest.msg.ResponseMsg;
import com.alibaba.fastjson2.JSON;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;


/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-06-24 14:54
 * @类说明：ProcessDefinitionRest
 * @修改记录：
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
public class ProcessDefinitionRestTest {
    @Autowired
    ProcessDefinitionRest processDefinitionRest;

    @Autowired
    ProcessDefinitionMapper processDefinitionMapper;

    // 使用JUnit框架中的ExpectedException类，用于测试异常;
    @Rule
    public ExpectedException thrown= ExpectedException.none();

    private static ProcessDefinition processDefeCreate;

    // 测试批量删除使用；
    private static ProcessDefinition processDefeCreate_1;

    private static ProcessDefinition processDefeUpdate;

    // Json串不合法；
    private static ProcessDefinition processDefeCreateInvalid;

    /**
     * 所有用例执行前准备工作
     */
    @BeforeClass
    public static void init() {
        // step1:构造流程定义参数;
        String processDefeStrCreate = "{\n" +
                "    \"id\": \"d48644cc-2c7a-4714-9900-18ab99e80b77\",\n" +
                "    \"name\": \"datax_job\",\n" +
                "    \"releaseState\": 0,\n" +
                "    \"projectId\": 1234,\n" +
                "\t\"typeId\": \"datax\",\n" +
                "\t\"type\": 0,\n" +
                "\t\"remark\": \"测试任务1\",\n" +
                "\t\"datasourceId\": 1,\n" +
                "\t\"processDefinitionJson\": \"{\\\"globalParams\\\":[],\\\"tasks\\\":[{\\\"type\\\":\\\"DATAX\\\",\\\"id\\\":\\\"tasks-24986\\\",\\\"name\\\":\\\"test\\\",\\\"params\\\":{\\\"customConfig\\\":0,\\\"dsType\\\":\\\"MYSQL\\\",\\\"dataSource\\\":1,\\\"dtType\\\":\\\"MYSQL\\\",\\\"dataTarget\\\":1,\\\"sql\\\":\\\"select * from db1;\\\",\\\"targetTable\\\":\\\"db2\\\",\\\"jobSpeedByte\\\":0,\\\"jobSpeedRecord\\\":1000,\\\"preStatements\\\":[],\\\"postStatements\\\":[]},\\\"description\\\":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"conditionResult\\\":{\\\"successNode\\\":[\\\"\\\"],\\\"failedNode\\\":[\\\"\\\"]},\\\"dependence\\\":{},\\\"maxRetryTimes\\\":\\\"0\\\",\\\"retryInterval\\\":\\\"1\\\",\\\"timeout\\\":{\\\"strategy\\\":\\\"\\\",\\\"interval\\\":null,\\\"enable\\\":false},\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"workerGroup\\\":\\\"default\\\",\\\"preTasks\\\":[]}],\\\"tenantId\\\":1,\\\"timeout\\\":0}\",\n" +
                "\t\"locations\": \"{\\\"tasks-34878\\\":{\\\"name\\\":\\\"datax自定义模板测试\\\",\\\"targetarr\\\":\\\"\\\",\\\"nodenumber\\\":\\\"0\\\",\\\"x\\\":424,\\\"y\\\":312}}\",\n" +
                "\t\"createdBy\": \"dcs\",\n" +
                "\t\"createdDate\": \"2020-08-04 11:23:17\",\n" +
                "\t\"lastUpdatedBy\":\"dcs\",\n" +
                "\t\"lastUpdateDate\": \"2020-08-04 11:23:17\"\n" +
                "}";
//        String processDefeStrCreate = "{\n" +
//                "    \"id\": \"d48644cc-2c7a-4714-9900-18ab99e80b77\",\n" +
//                "    \"name\": \"datax_job\",\n" +
//                "    \"releaseState\": 1,\n" +
//                "    \"projectId\": 1234,\n" +
//                "\t\"typeId\": \"datax\",\n" +
//                "\t\"type\": 0,\n" +
//                "\t\"remark\": \"测试任务1\",\n" +
//                "\t\"datasourceId\": 1,\n" +
//                "\t\"processDefinitionJson\": \"{\"globalParams\":[{\"direct\":\"IN\",\"prop\":\"syncTimeInterval\",\"type\":\"INTEGER\",\"value\":\"1800\"}],\"tasks\":[{\"conditionResult\":\"{}\",\"conditionsTask\":false,\"desc\":\"\",\"forbidden\":false,\"id\":\"tasks-29312\",\"maxRetryTimes\":0,\"name\":\"402880a47442d1040174437512340111-test\",\"params\":\"{\\\"httpCheckCondition\\\":\\\"STATUS_CODE_DEFAULT\\\",\\\"httpMethod\\\":\\\"GET\\\",\\\"resourceFilesList\\\":[],\\\"url\\\":\\\"http://192.168.0.36:10011/api/bdp/dcs/task/TaskRest/createTable/402880a47442d1040174437512340111\\\"}\",\"retryInterval\":1,\"runFlag\":\"NORMAL\",\"taskInstancePriority\":\"MEDIUM\",\"taskTimeoutParameter\":{\"enable\":false,\"interval\":0},\"type\":\"HTTP\",\"workerGroup\":\"default\"},{\"conditionResult\":\"{}\",\"conditionsTask\":false,\"depList\":[\"402880a47442d1040174437512340111-test\"],\"desc\":\"\",\"forbidden\":false,\"id\":\"tasks-12625\",\"maxRetryTimes\":0,\"name\":\"402880a47442d1040174437512340111\",\"params\":\"{\\\"customConfig\\\":1,\\\"dataSource\\\":0,\\\"dataTarget\\\":0,\\\"jobSpeedByte\\\":0,\\\"jobSpeedRecord\\\":0,\\\"json\\\":\\\"{\\\\\\\"job\\\\\\\":{\\\\\\\"setting\\\\\\\":{\\\\\\\"speed\\\\\\\":{\\\\\\\"channel\\\\\\\":3},\\\\\\\"errorLimit\\\\\\\":{\\\\\\\"record\\\\\\\":0,\\\\\\\"percentage\\\\\\\":0.02}},\\\\\\\"content\\\\\\\":[{\\\\\\\"reader\\\\\\\":{\\\\\\\"name\\\\\\\":\\\\\\\"mysqlreader\\\\\\\",\\\\\\\"parameter\\\\\\\":{\\\\\\\"username\\\\\\\":\\\\\\\"root\\\\\\\",\\\\\\\"password\\\\\\\":\\\\\\\"MQTM7Qk4O6YDEF\\\\\\\",\\\\\\\"column\\\\\\\":[\\\\\\\"id\\\\\\\",\\\\\\\"age\\\\\\\",\\\\\\\"address\\\\\\\"],\\\\\\\"splitPk\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"connection\\\\\\\":[{\\\\\\\"table\\\\\\\":[\\\\\\\"test\\\\\\\"],\\\\\\\"jdbcUrl\\\\\\\":[\\\\\\\"jdbc:mysql://192.168.0.24:3306/dolphinscheduler\\\\\\\"]}]}},\\\\\\\"writer\\\\\\\":{\\\\\\\"name\\\\\\\":\\\\\\\"mysqlwriter\\\\\\\",\\\\\\\"parameter\\\\\\\":{\\\\\\\"username\\\\\\\":\\\\\\\"root\\\\\\\",\\\\\\\"password\\\\\\\":\\\\\\\"MQTM7Qk4O6YDEF\\\\\\\",\\\\\\\"column\\\\\\\":[\\\\\\\"id\\\\\\\",\\\\\\\"age\\\\\\\",\\\\\\\"address\\\\\\\"],\\\\\\\"preSql\\\\\\\":[\\\\\\\"\\\\\\\"],\\\\\\\"connection\\\\\\\":[{\\\\\\\"table\\\\\\\":[\\\\\\\"test_wm\\\\\\\"],\\\\\\\"jdbcUrl\\\\\\\":\\\\\\\"jdbc:mysql://192.168.0.24:3306/dolphinscheduler\\\\\\\"}]}}}]}}\\\",\\\"localParametersMap\\\":{\\\"jobType\\\":{\\\"direct\\\":\\\"IN\\\",\\\"prop\\\":\\\"jobType\\\",\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"1\\\"}},\\\"localParams\\\":[{\\\"$ref\\\":\\\"$.localParametersMap.jobType\\\"}],\\\"resourceFilesList\\\":[]}\",\"preTasks\":\"[\\\"402880a47442d1040174437512340111-test\\\"]\",\"retryInterval\":1,\"runFlag\":\"NORMAL\",\"taskInstancePriority\":\"MEDIUM\",\"taskTimeoutParameter\":{\"enable\":false,\"interval\":0},\"type\":\"DATAX\",\"workerGroup\":\"default\"}],\"tenantId\":0,\"timeout\":0}\",\n" +
//                "\t\"locations\": \"{\\\"tasks-34878\\\":{\\\"name\\\":\\\"datax自定义模板测试\\\",\\\"targetarr\\\":\\\"\\\",\\\"nodenumber\\\":\\\"0\\\",\\\"x\\\":424,\\\"y\\\":312}}\",\n" +
//                "\t\"connects\": \"[{\"endPointSourceId\":\"tasks-29312\",\"endPointTargetId\":\"tasks-12625\"}]\"\n" +
//                "}\n";
        String processDefeStrCreate_1 = "{\n" +
                "    \"id\": \"d48644cc-2c7a-4714-9900-18ab99e80b88\",\n" +
                "    \"name\": \"datax_job\",\n" +
                "    \"releaseState\": 0,\n" +
                "    \"projectId\": 456,\n" +
                "\t\"typeId\": \"datax\",\n" +
                "\t\"type\": 0,\n" +
                "\t\"remark\": \"测试任务1\",\n" +
                "\t\"datasourceId\": 1,\n" +
                "\t\"processDefinitionJson\": \"{\\\"globalParams\\\":[],\\\"tasks\\\":[{\\\"type\\\":\\\"DATAX\\\",\\\"id\\\":\\\"tasks-24986\\\",\\\"name\\\":\\\"test\\\",\\\"params\\\":{\\\"customConfig\\\":0,\\\"dsType\\\":\\\"MYSQL\\\",\\\"dataSource\\\":1,\\\"dtType\\\":\\\"MYSQL\\\",\\\"dataTarget\\\":1,\\\"sql\\\":\\\"select * from db1;\\\",\\\"targetTable\\\":\\\"db2\\\",\\\"jobSpeedByte\\\":0,\\\"jobSpeedRecord\\\":1000,\\\"preStatements\\\":[],\\\"postStatements\\\":[]},\\\"description\\\":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"conditionResult\\\":{\\\"successNode\\\":[\\\"\\\"],\\\"failedNode\\\":[\\\"\\\"]},\\\"dependence\\\":{},\\\"maxRetryTimes\\\":\\\"0\\\",\\\"retryInterval\\\":\\\"1\\\",\\\"timeout\\\":{\\\"strategy\\\":\\\"\\\",\\\"interval\\\":null,\\\"enable\\\":false},\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"workerGroup\\\":\\\"default\\\",\\\"preTasks\\\":[]}],\\\"tenantId\\\":1,\\\"timeout\\\":0}\",\n" +
                "\t\"locations\": \"{\\\"tasks-34878\\\":{\\\"name\\\":\\\"datax自定义模板测试\\\",\\\"targetarr\\\":\\\"\\\",\\\"nodenumber\\\":\\\"0\\\",\\\"x\\\":424,\\\"y\\\":312}}\",\n" +
                "\t\"createdBy\": \"dcs\",\n" +
                "\t\"createdDate\": \"2020-08-04 11:23:17\",\n" +
                "\t\"lastUpdatedBy\":\"dcs\",\n" +
                "\t\"lastUpdateDate\": \"2020-08-04 11:23:17\"\n" +
                "}";
        String processDefeStrCreateInvalid = "{\n" +
                "    \"id\": \"d48644cc-2c7a-4714-9900-18ab99e80b77\",\n" +
                "    \"name\": \"datax_job\",\n" +
                "    \"releaseState\": 0,\n" +
                "    \"projectId\": 456,\n" +
                "\t\"typeId\": \"datax\",\n" +
                "\t\"type\": 0,\n" +
                "\t\"remark\": \"测试任务1\",\n" +
                "\t\"datasourceId\": 1,\n" +
                "\t\"processDefinitionJson\": \"{{\\\"globalParams\\\":[],\\\"tasks\\\":[{\\\"type\\\":\\\"DATAX\\\",\\\"id\\\":\\\"tasks-24986\\\",\\\"name\\\":\\\"test\\\",\\\"params\\\":{\\\"customConfig\\\":0,\\\"dsType\\\":\\\"MYSQL\\\",\\\"dataSource\\\":1,\\\"dtType\\\":\\\"MYSQL\\\",\\\"dataTarget\\\":1,\\\"sql\\\":\\\"select * from db1;\\\",\\\"targetTable\\\":\\\"db2\\\",\\\"jobSpeedByte\\\":0,\\\"jobSpeedRecord\\\":1000,\\\"preStatements\\\":[],\\\"postStatements\\\":[]},\\\"description\\\":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"conditionResult\\\":{\\\"successNode\\\":[\\\"\\\"],\\\"failedNode\\\":[\\\"\\\"]},\\\"dependence\\\":{},\\\"maxRetryTimes\\\":\\\"0\\\",\\\"retryInterval\\\":\\\"1\\\",\\\"timeout\\\":{\\\"strategy\\\":\\\"\\\",\\\"interval\\\":null,\\\"enable\\\":false},\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"workerGroup\\\":\\\"default\\\",\\\"preTasks\\\":[]}],\\\"tenantId\\\":1,\\\"timeout\\\":0}\",\n" +
                "\t\"locations\": \"{\\\"tasks-34878\\\":{\\\"name\\\":\\\"datax自定义模板测试\\\",\\\"targetarr\\\":\\\"\\\",\\\"nodenumber\\\":\\\"0\\\",\\\"x\\\":424,\\\"y\\\":312}}\",\n" +
                "\t\"createdBy\": \"dcs\",\n" +
                "\t\"createdDate\": \"2020-08-04 11:23:17\",\n" +
                "\t\"lastUpdatedBy\":\"dcs\",\n" +
                "\t\"lastUpdateDate\": \"2020-08-04 11:23:17\"\n" +
                "}";
        String processDefeStrUpdate = "{\n" +
                "    \"id\": \"d48644cc-2c7a-4714-9900-18ab99e80b77\",\n" +
                "    \"name\": \"datax_mysql_job\",\n" +
                "    \"releaseState\": 0,\n" +
                "    \"projectId\": 456,\n" +
                "\t\"typeId\": \"datax\",\n" +
                "\t\"type\": 0,\n" +
                "\t\"remark\": \"测试任务2\",\n" +
                "\t\"datasourceId\": 1,\n" +
                "\t\"processDefinitionJson\": \"{\\\"globalParams\\\":[],\\\"tasks\\\":[{\\\"type\\\":\\\"DATAX\\\",\\\"id\\\":\\\"tasks-24986\\\",\\\"name\\\":\\\"test\\\",\\\"params\\\":{\\\"customConfig\\\":0,\\\"dsType\\\":\\\"MYSQL\\\",\\\"dataSource\\\":1,\\\"dtType\\\":\\\"MYSQL\\\",\\\"dataTarget\\\":1,\\\"sql\\\":\\\"select * from db1;\\\",\\\"targetTable\\\":\\\"db2\\\",\\\"jobSpeedByte\\\":0,\\\"jobSpeedRecord\\\":1000,\\\"preStatements\\\":[],\\\"postStatements\\\":[]},\\\"description\\\":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"conditionResult\\\":{\\\"successNode\\\":[\\\"\\\"],\\\"failedNode\\\":[\\\"\\\"]},\\\"dependence\\\":{},\\\"maxRetryTimes\\\":\\\"0\\\",\\\"retryInterval\\\":\\\"1\\\",\\\"timeout\\\":{\\\"strategy\\\":\\\"\\\",\\\"interval\\\":null,\\\"enable\\\":false},\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"workerGroup\\\":\\\"default\\\",\\\"preTasks\\\":[]}],\\\"tenantId\\\":1,\\\"timeout\\\":0}\",\n" +
                "\t\"locations\": \"{\\\"tasks-34878\\\":{\\\"name\\\":\\\"datax自定义模板测试\\\",\\\"targetarr\\\":\\\"\\\",\\\"nodenumber\\\":\\\"0\\\",\\\"x\\\":424,\\\"y\\\":312}}\",\n" +
                "\t\"createdBy\": \"dcs\",\n" +
                "\t\"createdDate\": \"2020-08-04 11:23:17\",\n" +
                "\t\"lastUpdatedBy\":\"dcs\",\n" +
                "\t\"lastUpdateDate\": \"2020-08-04 11:23:17\"\n" +
                "}";
        processDefeCreate = JSON.parseObject(processDefeStrCreate, ProcessDefinition.class);
        processDefeCreate_1 = JSON.parseObject(processDefeStrCreate_1, ProcessDefinition.class);
        processDefeUpdate = JSON.parseObject(processDefeStrUpdate, ProcessDefinition.class);
        processDefeCreateInvalid = JSON.parseObject(processDefeStrCreateInvalid, ProcessDefinition.class);

        System.out.println(processDefeStrCreate);
    }

    /**
     * 单个测试用例运行前准备工作
     */
    @Before
    public void setUp() {}

    /**
     * 单个测试用例运行后销毁工作
     */
    @After
    public void tearDown() {}

    /**
     * 所有用例执行完成后准备工作
     */
    @AfterClass
    public static void destory() {}

    /***************************************************************
     ******************       正常场景测试用例       ******************
     ***************************************************************/
    /**
     * 创建流程定义；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testCreateProcessDefinition_1() throws Exception {
        // step1:准备阶段

        // step2:执行阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);

        // step3:验证阶段
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step4:清理阶段
        ResponseMsg<Boolean> deleteResponseMsg =
                processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
        Assert.assertEquals("200", deleteResponseMsg.getRetCode());
    }

    /**
     * 修改流程定义；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testUpdateDefinition_1() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step2:执行阶段
        ResponseMsg<Boolean> updateResponseMsg = processDefinitionRest.updateProcessDefinition(processDefeUpdate);

        // step3:验证阶段
        Assert.assertEquals("200", updateResponseMsg.getRetCode());

        // step4:清理阶段
        ResponseMsg<Boolean> deleteResponseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
        Assert.assertEquals("200", deleteResponseMsg.getRetCode());
    }

    /**
     * 删除流程定义；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testDeleteDefinition_1() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step2:执行阶段
        ResponseMsg<Boolean> deleteResponseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());

        // step3:验证阶段
        Assert.assertEquals("200", deleteResponseMsg.getRetCode());

        // step4:清理阶段
    }

    /**
     * 删除流程定义；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testDeleteDefinition_2() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step2:执行阶段
        ProcessDefinitionQuery processDefinitionQuery = new ProcessDefinitionQuery();
        processDefinitionQuery.setProcessDefinitionId(processDefeCreate.getId());
        ResponseMsg<Boolean> deleteResponseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());

        // step3:验证阶段
        Assert.assertEquals("200", deleteResponseMsg.getRetCode());

        // step4:清理阶段
    }

    /**
     * 批量删除流程定义；--新增接口
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testBatchDeleteDefinition_1() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());
        responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate_1);
        Assert.assertEquals("200", responseMsg.getRetCode());

        String batchDeleteProcessDefeIds = processDefeCreate.getId() + "," + processDefeCreate_1.getId();

        // step2:执行阶段
        ProcessDefinitionQuery processDefinitionQuery = new ProcessDefinitionQuery();
        processDefinitionQuery.setProcessDefinitionIds(batchDeleteProcessDefeIds);
//        processDefinitionRest.batchDeleteProcessDefinitionByIds(batchDeleteProcessDefeIds);
        processDefinitionRest.batchDeleteProcessDefinitionByIds2(processDefinitionQuery);

        // step3:验证阶段
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step4:清理阶段
    }

    /**
     * 批量删除流程定义；--新增接口
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testBatchDeleteDefinition_2() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());
        responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate_1);
        Assert.assertEquals("200", responseMsg.getRetCode());

        String batchDeleteProcessDefeIds = processDefeCreate.getId() + "," + processDefeCreate_1.getId();

        // step2:执行阶段
        processDefinitionRest.batchDeleteProcessDefinitionByIds(batchDeleteProcessDefeIds);

        // step3:验证阶段
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step4:清理阶段
    }

    /**
     * 启用/禁用流程定义
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testReleaseProcessDefinition_1() throws Exception {
//        // step1:准备阶段
//        ResponseMsg<Boolean> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
//        Assert.assertEquals("200", responseMsg.getRetCode());
//
//        // step2:执行阶段 and 验证阶段
//        // step2_1:启用流程定义;
//        responseMsg = processDefinitionRest.releaseProcessDefinition(processDefeCreate.getId(), 1);
//        Assert.assertEquals("200", responseMsg.getRetCode());
//        ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefeCreate.getId());
//        Assert.assertEquals(processDefinition.getReleaseState(), ReleaseState.ONLINE);
//
//        // step2_2:禁用流程定义;
//        responseMsg = processDefinitionRest.releaseProcessDefinition(processDefeCreate.getId(), 0);
//        Assert.assertEquals("200", responseMsg.getRetCode());
//        processDefinition = processDefinitionMapper.queryByDefineId(processDefeCreate.getId());
//        Assert.assertEquals(processDefinition.getReleaseState(), ReleaseState.OFFLINE);
//
//        // step3:清理阶段
//        responseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
//        Assert.assertEquals("200", responseMsg.getRetCode());
    }

    /***************************************************************
     ******************       异常场景测试用例       ******************
     ***************************************************************/
    /**
     * 创建流程定义时，参数为null，创建失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testCreateProcessDefinition_1_1() throws Exception {
        // step1:准备阶段

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("参数为空");
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(null);

        // step3:验证阶段

        // step4:清理阶段
    }

    /**
     * 创建流程定义时，JSON串不合法，创建失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testCreateProcessDefinition_1_2() throws Exception {
        // step1:准备阶段

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("Process Definition check json failed");
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreateInvalid);

        // step3:验证阶段

        // step4:清理阶段
    }

    /**
     * 修改流程定义，参数为null，修改失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testUpdateDefinition_1_1() throws Exception {
        // step1:准备阶段

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("参数为空");
        ResponseMsg<Boolean> responseMsg = processDefinitionRest.updateProcessDefinition(null);

        // step3:验证阶段
        Assert.assertNotEquals("200", responseMsg.getRetCode());

        // step4:清理阶段
    }

    /**
     * 修改流程定义，JSON串不合法，修改失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testUpdateDefinition_1_2() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("Process Definition check json failed");
        ResponseMsg<Boolean> updateResponseMsg =
                processDefinitionRest.updateProcessDefinition(processDefeCreateInvalid);

        // step3:验证阶段

        // step4:清理阶段
    }

    /**
     * 修改流程定义，流程定义不存在，修改失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testUpdateDefinition_1_3() throws Exception {
        // step1:准备阶段

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("process definition");
        ResponseMsg<Boolean> responseMsg = processDefinitionRest.updateProcessDefinition(processDefeCreate_1);

        // step3:验证阶段

        // step4:清理阶段
    }

    /**
     * 修改流程定义，流程定义状态为ONLINE，修改失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testUpdateDefinition_1_4() throws Exception {
//        // step1:准备阶段
//        ResponseMsg<Boolean> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
//        Assert.assertEquals("200", responseMsg.getRetCode());
//
//        responseMsg = processDefinitionRest.releaseProcessDefinition(processDefeCreate.getId(), 1);
//
//        // step2:执行阶段
//        thrown.expect(BusinessException.class);
//        thrown.expectMessage("Process Definition does not allow edit");
//        responseMsg = processDefinitionRest.updateProcessDefinition(processDefeUpdate);
//
//        // step3:验证阶段
//
//        // step4:清理阶段
//        responseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
//        Assert.assertEquals("200", responseMsg.getRetCode());
    }

    /**
     * 启用流程定义，状态不合法，启用失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testReleaseProcessDefinition_1_1() throws Exception {
//        // step1:准备阶段
//        ResponseMsg<Boolean> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
//        Assert.assertEquals("200", responseMsg.getRetCode());
//
//        // step2:执行阶段
//        thrown.expect(BusinessException.class);
//        thrown.expectMessage("request parameter");
//        responseMsg = processDefinitionRest.releaseProcessDefinition(processDefeCreate.getId(), 2);
//
//        // step3:验证阶段;
//
//        // step4:清理阶段
//        responseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
//        Assert.assertEquals("200", responseMsg.getRetCode());
    }

    /**
     * 启用流程定义，流程定义不存在，启用失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testReleaseProcessDefinition_1_2() throws Exception {
        // step1:准备阶段

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("process Definition is not exist");
        ResponseMsg<Boolean> responseMsg =
                processDefinitionRest.releaseProcessDefinition(processDefeCreate.getId(), 1);

        // step3:验证阶段;

        // step4:清理阶段
    }

    /**
     * 删除流程定义，流程定义ID非法，删除失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testDeleteDefinition_1_1() throws Exception {
        // step1:准备阶段

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("流程定义");
        ResponseMsg<Boolean> responseMsg = processDefinitionRest.deleteProcessDefinitionById(null);

        // step3:验证阶段

        // step4:清理阶段
    }

    /**
     * 删除流程定义，流程定义不存在，删除失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testDeleteDefinition_1_2() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("process Definition does not exist");
        ResponseMsg<Boolean> deleteResponseMsg =
                processDefinitionRest.deleteProcessDefinitionById(processDefeCreate_1.getId());

        // step3:验证阶段

        // step4:清理阶段
        deleteResponseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
        Assert.assertEquals("200", responseMsg.getRetCode());
    }

    /**
     * 删除流程定义，流程定义状态为ONLINE，删除失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testDeleteDefinition_1_3() throws Exception {
//        // step1:准备阶段
//        ResponseMsg<Boolean> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
//        Assert.assertEquals("200", responseMsg.getRetCode());
//        responseMsg = processDefinitionRest.releaseProcessDefinition(processDefeCreate.getId(), 1);
//        Assert.assertEquals("200", responseMsg.getRetCode());
//
//        // step2:执行阶段
//        thrown.expect(BusinessException.class);
//        thrown.expectMessage("process definition");
//        responseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
//
//        // step3:验证阶段
//
//        // step4:清理阶段
//        responseMsg = processDefinitionRest.deleteProcessDefinitionById(processDefeCreate.getId());
//        Assert.assertEquals("200", responseMsg.getRetCode());
    }

    /**
     * 批量删除流程定义,流程id字符串非法，删除失败；
     *
     * @throws Exception
     */
    @Test(timeout = 60 * 1000)
    public void testBatchDeleteDefinition_1_1() throws Exception {
        // step1:准备阶段
        ResponseMsg<String> responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate);
        Assert.assertEquals("200", responseMsg.getRetCode());
        responseMsg = processDefinitionRest.createProcessDefinition(processDefeCreate_1);
        Assert.assertEquals("200", responseMsg.getRetCode());

        String batchDeleteProcessDefeIds = processDefeCreate.getId() + "." + processDefeCreate_1.getId();

        // step2:执行阶段
        thrown.expect(BusinessException.class);
        thrown.expectMessage("batch delete process definition");
        processDefinitionRest.batchDeleteProcessDefinitionByIds(batchDeleteProcessDefeIds);

        // step3:验证阶段

        // step4:清理阶段
    }

}
